home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / sswitchxp152.exe / source / SpeedswitchXP / CPUOptions.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-07-13  |  9.1 KB  |  287 lines

  1. /*
  2.    SpeedswitchXP V1.5
  3.    - Windows XP CPU Frequency Control for Notebooks -
  4.  
  5.    Copyright(c) 2002-2005 Christian Diefer
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License version 2 as 
  9.    published by the Free Software Foundation.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #define _UNICODE
  22.  
  23. #include "stdafx.h"
  24. #include "SpeedswitchXP.h"
  25. #include "CPUOptions.h"
  26. #include "speedswitch.h"
  27.  
  28. #define TOOLTIP_ID 1
  29.  
  30. // CCPUOptions dialog
  31.  
  32. IMPLEMENT_DYNAMIC(CCPUOptions, CDialog)
  33. CCPUOptions::CCPUOptions(CWnd* pParent /*=NULL*/)
  34.     : CDialog(CCPUOptions::IDD, pParent)
  35.   , m_iDynThrottleAC(0)
  36.   , m_iDynThrottleDC(0)
  37.   , m_iCStateConfig(0)
  38. {
  39.   m_iTimeCheck[0] = 0;
  40.   m_iTimeCheck[1] = 0;
  41.   m_iTimeCheck[2] = 0;
  42.   m_iDemoteLimit[0] = 0;
  43.   m_iDemoteLimit[1] = 0;
  44.   m_iDemoteLimit[2] = 0;
  45.   m_iPromoteLimit[0] = 0;
  46.   m_iPromoteLimit[1] = 0;
  47.   m_iPromoteLimit[2] = 0;
  48.   m_iDemotePercent[0] = 0;
  49.   m_iDemotePercent[1] = 0;
  50.   m_iDemotePercent[2] = 0;
  51.   m_iPromotePercent[0] = 0;
  52.   m_iPromotePercent[1] = 0;
  53.   m_iPromotePercent[2] = 0;
  54.   m_iAllowDemotion[0] = 1;
  55.   m_iAllowDemotion[1] = 1;
  56.   m_iAllowDemotion[2] = 1;
  57.   m_iAllowPromotion[0] = 1;
  58.   m_iAllowPromotion[1] = 1;
  59.   m_iAllowPromotion[2] = 1;
  60. }
  61.  
  62. CCPUOptions::~CCPUOptions()
  63. { }
  64.  
  65. void CCPUOptions::DoDataExchange(CDataExchange* pDX)
  66. {
  67.   CDialog::DoDataExchange(pDX);
  68.   DDX_CBIndex(pDX, IDC_COMBO1, m_iDynThrottleAC);
  69.   DDX_CBIndex(pDX, IDC_COMBO2, m_iDynThrottleDC);
  70.   DDX_CBIndex(pDX, IDC_COMBO3, m_iCStateConfig);
  71.   DDX_Text(pDX, IDC_EDIT1, m_iTimeCheck[0]);
  72.   DDX_Text(pDX, IDC_EDIT2, m_iTimeCheck[1]);
  73.   DDX_Text(pDX, IDC_EDIT3, m_iTimeCheck[2]);
  74.   DDX_Text(pDX, IDC_EDIT4, m_iDemoteLimit[0]);
  75.   DDX_Text(pDX, IDC_EDIT13, m_iDemoteLimit[1]);
  76.   DDX_Text(pDX, IDC_EDIT14, m_iDemoteLimit[2]);
  77.   DDX_Text(pDX, IDC_EDIT5, m_iPromoteLimit[0]);
  78.   DDX_Text(pDX, IDC_EDIT6, m_iPromoteLimit[1]);
  79.   DDX_Text(pDX, IDC_EDIT7, m_iPromoteLimit[2]);
  80.   DDX_Text(pDX, IDC_EDIT8, m_iDemotePercent[0]);
  81.   DDX_Text(pDX, IDC_EDIT15, m_iDemotePercent[1]);
  82.   DDX_Text(pDX, IDC_EDIT16, m_iDemotePercent[2]);
  83.   DDX_Text(pDX, IDC_EDIT9, m_iPromotePercent[0]);
  84.   DDX_Text(pDX, IDC_EDIT17, m_iPromotePercent[1]);
  85.   DDX_Text(pDX, IDC_EDIT18, m_iPromotePercent[2]);
  86.   DDX_CBIndex(pDX, IDC_COMBO9, m_iAllowDemotion[0]);
  87.   DDX_CBIndex(pDX, IDC_COMBO10, m_iAllowDemotion[1]);
  88.   DDX_CBIndex(pDX, IDC_COMBO11, m_iAllowDemotion[2]);
  89.   DDX_CBIndex(pDX, IDC_COMBO12, m_iAllowPromotion[0]);
  90.   DDX_CBIndex(pDX, IDC_COMBO13, m_iAllowPromotion[1]);
  91.   DDX_CBIndex(pDX, IDC_COMBO14, m_iAllowPromotion[2]);
  92. }
  93.  
  94. BOOL CCPUOptions::OnInitDialog()
  95. {
  96.     CDialog::OnInitDialog();
  97.  
  98.   fillCStateArray( m_iCStateConfig );
  99.  
  100.   CString s1;
  101.  
  102.   s1.LoadStringW( IDS_CPOL1 );
  103.   addToolTip( 0, IDC_COMBO3, s1 );
  104.  
  105.   s1.LoadStringW( IDS_CPOL2 );
  106.   addToolTip( 1, IDC_EDIT1, s1 );
  107.   addToolTip( 2, IDC_EDIT2, s1 );
  108.   addToolTip( 3, IDC_EDIT3, s1 );
  109.  
  110.   s1.LoadStringW( IDS_CPOL3 );
  111.   addToolTip( 4, IDC_EDIT4, s1 );
  112.   addToolTip( 5, IDC_EDIT13, s1 );
  113.   addToolTip( 6, IDC_EDIT14, s1 );
  114.  
  115.   s1.LoadStringW( IDS_CPOL4 );
  116.   addToolTip( 7, IDC_EDIT5, s1 );
  117.   addToolTip( 8, IDC_EDIT6, s1 );
  118.   addToolTip( 9, IDC_EDIT7, s1 );
  119.  
  120.   s1.LoadStringW( IDS_CPOL5 );
  121.   addToolTip( 10, IDC_EDIT8, s1 );
  122.   addToolTip( 11, IDC_EDIT15, s1 );
  123.   addToolTip( 12, IDC_EDIT16, s1 );
  124.  
  125.   s1.LoadStringW( IDS_CPOL6 );
  126.   addToolTip( 13, IDC_EDIT9, s1 );
  127.   addToolTip( 14, IDC_EDIT17, s1 );
  128.   addToolTip( 15, IDC_EDIT18, s1 );
  129.  
  130.   s1.LoadStringW( IDS_CPOL7 );
  131.   addToolTip( 16, IDC_COMBO9, s1 );
  132.   addToolTip( 17, IDC_COMBO10, s1 );
  133.   addToolTip( 18, IDC_COMBO11, s1 );
  134.  
  135.   s1.LoadStringW( IDS_CPOL8 );
  136.   addToolTip( 19, IDC_COMBO12, s1 );
  137.   addToolTip( 20, IDC_COMBO13, s1 );
  138.   addToolTip( 21, IDC_COMBO14, s1 );
  139.  
  140.   return TRUE;
  141. }
  142.  
  143. BOOL CCPUOptions::PreTranslateMessage( MSG* pMsg ) 
  144. {
  145.   for( int i=0; i<22; i++ )
  146.     m_tToolTip[i].RelayEvent( pMsg );
  147.  
  148.   return CDialog::PreTranslateMessage( pMsg );
  149. }
  150.  
  151.  
  152. BEGIN_MESSAGE_MAP(CCPUOptions, CDialog)
  153.   ON_CBN_SELCHANGE(IDC_COMBO3, OnCbnSelchangeCombo3)
  154. END_MESSAGE_MAP()
  155.  
  156.  
  157. // CCPUOptions message handlers
  158. void CCPUOptions::setVars()
  159. {
  160.   polAC = mach.ProcessorPolicyAc;
  161.   polDC = mach.ProcessorPolicyDc;
  162. //  polAC.PolicyCount = 2;
  163.   m_iCStateConfig = 0;
  164.   m_iDynThrottleAC = mach.ProcessorPolicyAc.DynamicThrottle;
  165.   m_iDynThrottleDC = mach.ProcessorPolicyDc.DynamicThrottle;
  166.   cpu = FALSE;
  167. }
  168.  
  169. void CCPUOptions::getVars()
  170. {
  171.   if( cpu )
  172.   {
  173.     mach.ProcessorPolicyAc = polAC;
  174.     mach.ProcessorPolicyDc = polDC;
  175.   }
  176. }
  177.  
  178.  
  179. void CCPUOptions::OnCbnSelchangeCombo3()
  180. {
  181.   UpdateData();
  182.   applyChanges( m_iCStateConfig==0 ? 1 : 0 );   // invertieren, da schon geΣndert
  183.   fillCStateArray( m_iCStateConfig );
  184.   UpdateData( FALSE );
  185. }
  186.  
  187. void CCPUOptions::fillCStateArray( int config )
  188. {
  189.   PROCESSOR_POWER_POLICY* pol;
  190.  
  191.   if( config == 0 )   // AC
  192.     pol = &polAC;
  193.   else
  194.     pol = &polDC;
  195.  
  196.   for( int i=0; i<(int)pol->PolicyCount; i++ )
  197.   {
  198.     m_iTimeCheck[i] = pol->Policy[i].TimeCheck;
  199.     m_iDemoteLimit[i] = pol->Policy[i].DemoteLimit;
  200.     m_iPromoteLimit[i] = pol->Policy[i].PromoteLimit;
  201.     m_iDemotePercent[i] = pol->Policy[i].DemotePercent;
  202.     m_iPromotePercent[i] = pol->Policy[i].PromotePercent;
  203.     m_iAllowDemotion[i] = pol->Policy[i].AllowDemotion ? 0 : 1;
  204.     m_iAllowPromotion[i] = pol->Policy[i].AllowPromotion ? 0 : 1;
  205.   }
  206.  
  207.   for( int i=pol->PolicyCount; i<3; i++ )
  208.   {
  209.     m_iTimeCheck[i] = 0;
  210.     m_iDemoteLimit[i] = 0;
  211.     m_iPromoteLimit[i] = 0;
  212.     m_iDemotePercent[i] = 0;
  213.     m_iPromotePercent[i] = 0;
  214.     m_iAllowDemotion[i] = 1;
  215.     m_iAllowPromotion[i] = 1;
  216.   }
  217.  
  218.   ((CWnd*)GetDlgItem(IDC_EDIT1))->EnableWindow( pol->PolicyCount>0 );
  219.   ((CWnd*)GetDlgItem(IDC_EDIT4))->EnableWindow( pol->PolicyCount>0 );
  220.   ((CWnd*)GetDlgItem(IDC_EDIT5))->EnableWindow( pol->PolicyCount>0 );
  221.   ((CWnd*)GetDlgItem(IDC_EDIT8))->EnableWindow( pol->PolicyCount>0 );
  222.   ((CWnd*)GetDlgItem(IDC_EDIT9))->EnableWindow( pol->PolicyCount>0 );
  223.   ((CWnd*)GetDlgItem(IDC_COMBO9))->EnableWindow( pol->PolicyCount>0 );
  224.   ((CWnd*)GetDlgItem(IDC_COMBO12))->EnableWindow( pol->PolicyCount>0 );
  225.  
  226.   ((CWnd*)GetDlgItem(IDC_EDIT2))->EnableWindow( pol->PolicyCount>1 );
  227.   ((CWnd*)GetDlgItem(IDC_EDIT13))->EnableWindow( pol->PolicyCount>1 );
  228.   ((CWnd*)GetDlgItem(IDC_EDIT6))->EnableWindow( pol->PolicyCount>1 );
  229.   ((CWnd*)GetDlgItem(IDC_EDIT15))->EnableWindow( pol->PolicyCount>1 );
  230.   ((CWnd*)GetDlgItem(IDC_EDIT17))->EnableWindow( pol->PolicyCount>1 );
  231.   ((CWnd*)GetDlgItem(IDC_COMBO10))->EnableWindow( pol->PolicyCount>1 );
  232.   ((CWnd*)GetDlgItem(IDC_COMBO13))->EnableWindow( pol->PolicyCount>1 );
  233.  
  234.   ((CWnd*)GetDlgItem(IDC_EDIT3))->EnableWindow( pol->PolicyCount>2 );
  235.   ((CWnd*)GetDlgItem(IDC_EDIT14))->EnableWindow( pol->PolicyCount>2 );
  236.   ((CWnd*)GetDlgItem(IDC_EDIT7))->EnableWindow( pol->PolicyCount>2 );
  237.   ((CWnd*)GetDlgItem(IDC_EDIT16))->EnableWindow( pol->PolicyCount>2 );
  238.   ((CWnd*)GetDlgItem(IDC_EDIT18))->EnableWindow( pol->PolicyCount>2 );
  239.   ((CWnd*)GetDlgItem(IDC_COMBO11))->EnableWindow( pol->PolicyCount>2 );
  240.   ((CWnd*)GetDlgItem(IDC_COMBO14))->EnableWindow( pol->PolicyCount>2 );
  241. }
  242.  
  243. void CCPUOptions::applyChanges( int config )
  244. {
  245.   PROCESSOR_POWER_POLICY* pol;
  246.  
  247.   if( config == 0 )   // AC
  248.     pol = &polAC;
  249.   else
  250.     pol = &polDC;
  251.  
  252.   for( int i=0; i<(int)pol->PolicyCount; i++ )
  253.   {
  254.     if( m_iDemotePercent[i]<0 || m_iDemotePercent[i]>100 )
  255.       m_iDemotePercent[i] = pol->Policy[i].DemotePercent;
  256.  
  257.     if( m_iPromotePercent[i]<0 || m_iPromotePercent[i]>100 )
  258.       m_iPromotePercent[i] = pol->Policy[i].PromotePercent;
  259.  
  260.     if( m_iTimeCheck[i] != pol->Policy[i].TimeCheck
  261.     ||  m_iDemoteLimit[i] != pol->Policy[i].DemoteLimit
  262.     ||  m_iPromoteLimit[i] != pol->Policy[i].PromoteLimit
  263.     ||  m_iDemotePercent[i] != pol->Policy[i].DemotePercent
  264.     ||  m_iPromotePercent[i] != pol->Policy[i].PromotePercent
  265.     ||  (m_iAllowDemotion[i]==0?1:0) != pol->Policy[i].AllowDemotion
  266.     ||  (m_iAllowPromotion[i]==0?1:0) != pol->Policy[i].AllowPromotion )
  267.     {
  268.       cpu = TRUE;
  269.       pol->Policy[i].TimeCheck = m_iTimeCheck[i];
  270.       pol->Policy[i].DemoteLimit = m_iDemoteLimit[i];
  271.       pol->Policy[i].PromoteLimit = m_iPromoteLimit[i];
  272.       pol->Policy[i].DemotePercent = m_iDemotePercent[i];
  273.       pol->Policy[i].PromotePercent = m_iPromotePercent[i];
  274.       pol->Policy[i].AllowDemotion = (m_iAllowDemotion[i]==0?1:0);
  275.       pol->Policy[i].AllowPromotion = (m_iAllowPromotion[i]==0?1:0);
  276.     }    
  277.   }
  278. }
  279.  
  280. void CCPUOptions::addToolTip( int no, int id, CString str )
  281. {
  282.   CWnd* wnd = GetDlgItem( id );
  283.   CRect rect; 
  284.   wnd->GetClientRect( rect );
  285.   m_tToolTip[no].Create( wnd );
  286.   m_tToolTip[no].AddTool( wnd, str, rect, TOOLTIP_ID );
  287. }